package com.inspectortime.webapp.inspector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.inspectortime.domain.Employee;
import com.inspectortime.repository.Factory;
import com.inspectortime.repository.Repository;

/**
 * Add a new Inspector to an existing company
 * 
 * @author bones
 *
 */
public abstract class AddEmployeeController extends SimpleFormController {
	
	protected Repository repository;
	protected Factory factory;

	protected ModelAndView onSubmit(HttpServletRequest request,	HttpServletResponse response, Object command, BindException errors)
		throws Exception {
		
		Employee employee = (Employee) command;
		employee.setCleartextPassword(employee.getPassword());
		employee.save();
		
		return new ModelAndView(getSuccessView(), errors.getModel());
	}
	
	
	
	public void setRepository(Repository repository) {
		this.repository = repository;
	}
	
	public void setFactory(Factory factory) {
		this.factory = factory;
	}

}
